package com.laikan.reader.core.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.laikan.reader.core.LaikanBaseAdapter;
import com.laikan.reader.R;
import com.laikan.reader.core.bean.ReplyBean;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class ReplyAdatper extends LaikanBaseAdapter<ReplyBean> {

    public ReplyAdatper(Context context, ArrayList<ReplyBean> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.lk_reply_item, null);
            holder.person_img = (com.facebook.drawee.view.SimpleDraweeView)convertView.findViewById(R.id.head_reviewer_img);
            holder.username = (TextView)convertView.findViewById(R.id.head_reviewer_name);
            holder.reply_time = (TextView)convertView.findViewById(R.id.reply_time);
            holder.reply_content = (TextView)convertView.findViewById(R.id.reply_content);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        //       KLog.d("TAG", "tupian = " +datas.get(position).getReplyUserIcon()+"-----------------------------");
        if (null != (datas.get(position).getReplyUserIcon())) {
            holder.person_img.setImageURI(Uri.parse(datas.get(position).getReplyUserIcon()));
        }
        if (null != (datas.get(position).getReplyUserName())) {
            holder.username.setText(datas.get(position).getReplyUserName());
        }
        if (null != (datas.get(position).getReplyCreateTime())) {
            SimpleDateFormat sf = new SimpleDateFormat("MM-dd HH:mm");
            holder.reply_time.setText(sf.format(new Date(Long.parseLong(datas.get(position).getReplyCreateTime()))));
//            holder.reply_time.setText(PublicUtil.timeStamp2DateFormatString(datas.get(position).getReplyCreateTime(), "MM-dd HH:mm"));
        }
        if (null != (datas.get(position).getReplyContent())) {
            holder.reply_content.setText(datas.get(position).getReplyContent());
        }
        return convertView;
    }

    private class ViewHolder {

        private com.facebook.drawee.view.SimpleDraweeView person_img;
        private TextView username, reply_time, reply_content;
    }

}
